#include "ResourceHelper.h"

static const wchar_t STRINGMISSING[] = {17, '*', 'S', 'T', 'R', 'I', 'N', 'G', ' ', 'M', 'I', 'S', 'S', 'I', 'N', 'G', '*', 0};

__declspec(naked) WCHAR* __fastcall GetStringAreaW(UINT resource_id)
{
	__asm{
		push ecx       /* Save resource_id */
		shr ecx,4
		inc ecx
		push 6         /* FindResourceW - RT_STRING */
		push ecx       /* FindResourceW - RESID */
		push 0         /* FindResourceW - NULL */
		call dword ptr[FindResourceW]
		test eax,eax
		jz GetStringAreaWExit
		push eax       /* LoadResource - hrsrc */
		push 0         /* LoadResource - NULL */
		call dword ptr[LoadResource]
		test eax,eax
		jz GetStringAreaWExit
		push eax       /* LockResource - hmem */
		call dword ptr[LockResource]
		pop ecx
		and ecx,0000000Fh
GetStringAreaWLoop:
		jz GetStringAreaWReturn
		movzx edx,word ptr[eax]
		lea eax,[eax+edx*2+2]
		dec ecx
		jmp GetStringAreaWLoop
GetStringAreaWExit:
		pop ecx
StringNotFound:
		mov eax,offset STRINGMISSING
GetStringAreaWReturn:
		or word ptr[eax],0
		jz StringNotFound
		ret
	}
}